const wheel = document.querySelector('.wheel'),
      spinBtn = document.querySelector('.spinBtn');
let value = [45, 135, 225, 315, 405, 495, 585, 675];
let spinsLeft = 3;

spinBtn.onclick =  function() {
    if (spinsLeft > 0) {
        const rotateNum = Math.ceil(Math.random() * 10); // 随机的旋转圈数
        const offset = Math.ceil(Math.random() * 360 * rotateNum); // 随机的偏移角度，考虑到多圈旋转
        const finalAngle = offset; // 最终的旋转角度
		console.log("+++"+rotateNum);
		console.log("+++"+offset);
        rotateWheel(finalAngle); // 调用旋转转盘函数

        spinsLeft--;
    } else {
        alert("每天只能转动三次！"); // 提示每天只能转动三次
    }
}

function rotateWheel(angle) {
    wheel.style.transition = 'transform 5s ease-out'; // 添加过渡效果
    wheel.style.transform = `rotate(${angle}deg)`; // 旋转转盘

    setTimeout(() => {
        const stopAngle = angle % 360; // 计算准确的停止角度
        const selectedNumber = calculateSelectedNumber(stopAngle); // 获取停止角度对应的奖项
        console.log(selectedNumber);
    }, 5000); // 等待5秒后执行
}

function calculateSelectedNumber(angle) {
     let index;
        if (angle >= 22.5 && angle < 67.5) {
            index = 7;
        } else if (angle >= 67.5 && angle < 112.5) {
            index = 6;
        } else if (angle >= 112.5 && angle < 157.5) {
            index = 5;
        } else if(angle >= 157.5 && angle < 202.5){
            index = 4;
        }else if(angle >= 202.5 && angle < 247.5){
            index = 3;
        }else if(angle >= 247.5 && angle < 292.5){
            index = 2;
        }else if(angle >= 292.5 && angle < 337.5){
            index = 1;
        }else{
			index=0;
		}
    return document.querySelectorAll('.number span')[index].innerText; // 返回对应角度的奖项
}
